//===============================
//  功能 ：备注 
//  作者 ：上中野辅亚瑟王 
//  创建时间 ：2025-06-18  18-19-58 
//  Unity版本  ：2019.4.35f1 
//  变更时间 :  2025-06-18  18-19-58 
//===============================





using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace Tools.UI
{
	[RequireComponent(typeof(RectTransform))]
	public class MinMaxSlider : Selectable
	{
		public enum HandleType
		{
			Both,
			Min,
			Max
		}


		private const float FLOAT_TOL = 0.01f;
		// values
		[Header("Limits")]
		[SerializeField] private float minLimit;
		[SerializeField] private float maxLimit = 100;

		[Header("Values")]
		public bool wholeNumbers;
		[SerializeField] private float minValue = 25;
		[SerializeField] private float maxValue = 75;

		public MinMaxValues Values => new MinMaxValues(minValue, maxValue, minLimit, maxLimit);


		[SerializeField]
		private RectTransform fillAreaRect;
		[SerializeField]
		private RectTransform fillRect;



        private void Update()
        {
			UpdateMiddleGraphic();
		}

        private void UpdateMiddleGraphic()
		{
			if (!fillRect)
				return;

			fillRect.anchorMin = Vector2.zero;
			fillRect.anchorMax = Vector2.one;
			fillRect.offsetMin = new Vector2(minValue, 0);
			fillRect.offsetMax = new Vector2(maxValue, 0);

		}


		[Serializable]
		public struct MinMaxValues
		{
			public float minValue, maxValue, minLimit, maxLimit;
			public static MinMaxValues DEFUALT = new MinMaxValues(25, 75, 0, 100);


			public MinMaxValues(float minValue, float maxValue, float minLimit, float maxLimit)
			{
				this.minValue = minValue;
				this.maxValue = maxValue;
				this.minLimit = minLimit;
				this.maxLimit = maxLimit;
			}

			/// <summary>
			/// Constructor for when values equal limits
			/// </summary>
			/// <param name="minValue"></param>
			/// <param name="maxValue"></param>
			public MinMaxValues(float minValue, float maxValue)
			{
				this.minValue = minValue;
				this.maxValue = maxValue;
				this.minLimit = minValue;
				this.maxLimit = maxValue;
			}

			public bool IsAtMinAndMax()
			{
				return Math.Abs(minValue - minLimit) < FLOAT_TOL && Math.Abs(maxValue - maxLimit) < FLOAT_TOL;
			}

			public override string ToString()
			{
				return $"Values(min:{minValue}, max:{maxValue}) | Limits(min:{minLimit}, max:{maxLimit})";
			}
		}


	}
}

